java - 在 JUnit 测试中尝试 catch
全部标签 我正在尝试测试一个简单的索引View,其中包含以下代码:-ifcan?:destroy,MyModel%thOptionsMyModelsController有以下选项(InheritedResources+CanCan+Devise):classMyModelsController:project运行规范时,它在行崩溃-如果可以?:destroy,我的模型Failure/Error:renderActionView::Template::Error:undefinedmethod`authenticate'fornil:NilClass没有回溯,没有任何依据......我想也许我在测
我认为我的用户工厂正在构建时出现问题。我收到一条错误消息,提示密码不能为空,但它在我的factories.rb中明确设置。有人看到我可能遗漏的任何东西吗?或者规范失败的原因?我为我的其他模型之一做了非常相似的事情,而且似乎成功了。我不确定错误是否是由设计引起的。Rspec错误UsershouldcreateanewinstanceofausergivenvalidattributesFailure/Error:User.create!(@user.attributes)ActiveRecord::RecordInvalid:Validationfailed:Passwordcan'tb
我在控制台服务应用中使用system.threading.timer,并尝试每天同时制作计时器。最初,如果我在时间之前启动该应用程序,我会很好。就像我的时间是10:05,我从10:00启动该应用程序,我们很好。但是,如果我从10:06开始,我就不知道如何告诉时间台下24小时。谢谢你的帮助!publicvoidSetUpTimer(TimeSpanalertTime){DateTimecurrent=DateTime.Now;TimeSpantimeToGo=alertTime-current.TimeOfDay;if(timeToGo{EventLog.WriteEntry("MhyApp",
我正在尝试测试一个rake任务,它在其中使用了一个事件记录。require'spec_helper'require'rake'loadFile.join(Rails.root,'lib','tasks','survey.rake')describe"surveyraketasks"dodescribe"survey:send_report"doit"shouldsendareport"doRake::Task['survey:send_report'].invokeendendend当我运行此规范rspecspec/lib/survey_spec.rb时,出现此错误“RuntimeEr
我有一个方法可以做这样的事情:defsome_methodchance=rand(4)ifchance==1do#logichereelse#anotherlogichereendend当我用RSpec测试这个方法时,里面的rand(4)总是生成0。我不是在测试Rails的rand方法,我是在测试我的方法.测试我的方法的常见做法是什么? 最佳答案 我会考虑两种方法:方法1:在before:eachblock中使用srand(seed)中已知的种子值:before:eachdosrand(67809)end这适用于所有Ruby版本,并
我看到我可以像这样用rspec测试路由:get("/").shouldroute_to("welcome#index")但我有基于主机名或部分主机名的约束,并在多个主机名之间重定向。测试时如何指定主机名?如何使用正确的配置运行测试?我尝试打印root_url并得到:Missinghosttolinkto!Pleaseprovidethe:hostparameter,setdefault_url_options[:host],orset:only_pathtotrue 最佳答案 同样的错误发生在我每次运行rspecspec/整个错误实
我正在寻求使我的Rails测试更快。我只有520个测试,但它们在bash中运行需要62秒,在Rubymine中运行需要82秒。作为典型Controller测试的示例,我使用此代码以@user身份登录并在CommentsController中为我的RSpecController测试创建基本的@comment:before(:each)do@user=Factory.create(:user)sign_in@user@comment=Factory.create(:comment)end您可能会意识到...这很慢。它构建了一个@user,但也为该用户构建了关联。@comment也是如此。所
Ruby是否有明确的规范,类似于Java的Java语言规范。谷歌搜索ruby语言规范提供http://ruby-std.netlab.jp/结果,该站点已关闭,我不确定它是否是最新的 最佳答案 有adraft对于formalspecificationruby。它由OpenStandardsPromotionCenter开发的Information-TechnologyPromotionAgency(日本政府机构)提交给JapaneseIndustrialStandardsCommittee然后进一步到InternationalO
我有以下类(class):我想确保类url只为所有实例设置一次。classDataFactory@@url=nildefinitialize()beginif@@url.nil?Rails.logger.debug"Settingurl"@@url=MY_CONFIG["myvalue"]endrescueExceptionraiseDataFactoryError,"Error!"endendend我有两个测试:it"shouldlogamessage"doAPP_CONFIG={"myvalue"=>"test"}Rails.stub(:logger).and_return(log
在设计文档中,他们提供了有关在测试Controller时如何访问current_user的提示:https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29但是,在进行功能测试时呢?我正在尝试测试我的一个Controller的创建方法,并且在该Controller中使用了current_user变量。问题是devise中建议的宏使用了@request变量,并且对于功能规范来说它是nil。什么是解决方法?编辑:这是我目前的规范:feature